home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / QD32Exists.c < prev    next >
Text File  |  1994-09-10  |  3KB  |  91 lines

  1. /* QD32Exists.c
  2. Apple suggests, and I agree, that all new programs should use the new Gestalt
  3. manager, that is documented in Inside Mac VI. It's very easy to use, as
  4. illustrated below.
  5.  
  6. The only subtlety in the code below is that if Gestalt() is NOT present--because
  7. the program is being run under a System before 6.04--then the compiler's glue
  8. code is supposed to cause Gestalt() to return with an error code, rather than
  9. crash because of a missing trap. Same goes for the call to SysEnvirons(), which
  10. should be present on all Systems after 4.1.
  11.  
  12. The answers are cached, so subsequent calls after the first will be quick.
  13.  
  14. HISTORY:
  15. 4/21/90    dgp    added statics to avoid wasting time recomputing this.
  16. 2/27/91 dgp    added QD8Exists().
  17. 4/15/91 dgp    added NewPaletteManager() to determine whether the calls documented
  18.             in the Palette Manager chapter of Inside Mac VI are available.
  19. 8/24/91    dgp    Made compatible with THINK C 5.0.
  20. 3/27/92    dgp    Use Gestalt() instead of SysEnvirons(), as recommended by Apple. 
  21. 9/15/92 dgp Changed NewPaletteManager() to check only the system version. Apple
  22.             documents had indicated to me that the new palette manager calls
  23.             would be available in any system if QD32 were present, so I had
  24.             ORed that in. However, I find that the HasDepth() call fails on
  25.             my Mac IIci (which has QD32 in ROM) under System 6.04. So the new
  26.             test is slightly more conservative than the former.
  27. 4/17/93    dgp    Corrected capitalization of "VideoToolbox.h" so that
  28.             THINK C will use the pre-compiled header.
  29. */
  30.  
  31. #include "VideoToolbox.h"
  32. static void Exists(void);        /* Internal routine to do the work, once.  */
  33. static void OldExists(void);    /* Handle Systems 4.1 to 6.03  */
  34.  
  35. static Boolean firstTime=1,qD8Exists=0,qD32Exists=0,newPaletteManager=0;
  36.  
  37. Boolean QD32Exists(void)        /* Does 32-bit quickdraw exist? */
  38. {
  39.     if(firstTime)Exists();
  40.     return qD32Exists;
  41. }
  42.  
  43. Boolean QD8Exists(void)            /* Does color quickdraw exist? */
  44. {
  45.     if(firstTime)Exists();
  46.     return qD8Exists;
  47. }
  48.  
  49. Boolean NewPaletteManager(void)    /* Does it exist? */
  50. {
  51.     if(firstTime)Exists();
  52.     return newPaletteManager;
  53. }
  54.  
  55. static void Exists(void)        /* Internal routine to do the work, once.  */
  56. {
  57.     int error;
  58.     long version;
  59.  
  60.     firstTime=0;
  61.     error=Gestalt(gestaltVersion,&version);    /* Is Gestalt available? */
  62.     if(error){
  63.         OldExists();                        /* No. Try SysEnvirons(). */
  64.         return;
  65.     }
  66.     Gestalt(gestaltQuickdrawVersion,&version);
  67.     qD8Exists = version>=gestalt8BitQD;
  68.     qD32Exists = version>=gestalt32BitQD;
  69.     Gestalt(gestaltSystemVersion,&version);
  70.     newPaletteManager = version>=0x605;
  71. }
  72.  
  73. #define missingTrap 0xA89F
  74. #define QD32Trap    0xAB03
  75.  
  76. static void OldExists(void)    /* Handle Systems 4.1 to 6.03  */
  77. {
  78.     int error;
  79.     SysEnvRec theWorld;
  80.     
  81.     firstTime=0;
  82.     error=SysEnvirons(1,&theWorld);        /* Is SysEnvirons available? */
  83.     if(error)return;                    /* No. */
  84.     qD8Exists=theWorld.hasColorQD;
  85.     if(qD8Exists){
  86.         if(NGetTrapAddress(QD32Trap,ToolTrap) != NGetTrapAddress(missingTrap,ToolTrap))
  87.             qD32Exists=1;
  88.         newPaletteManager=theWorld.systemVersion>=0x605;
  89.     }
  90. }
  91.